import { isNull } from '../utils/validate'

export function iconNameFilter (icon) {
  if (isNull(icon)) return 'apple'
  return icon
}

export function minute2str (m) {
  if (typeof m === 'number') {
    if (m < 60) {
      return m + '分钟'
    } else if (m >= 60 && m < 60 * 24) {
      let h = parseInt(m / 60)
      return h + '小时' + (m - h * 60) + '分钟'
    } else if (m >= 60 * 24 && m < 60 * 24 * 30) {
      let aDay = 60 * 24
      let day = parseInt(m / aDay)
      return day + '天' + minute2str(m - (day * aDay))
    } else if (m >= 60 * 24 * 30 && m < 60 * 24 * 30 * 12) {
      let aMonth = 60 * 24 * 30
      let mon = parseInt(m / aMonth)
      return mon + '月' + minute2str(m - (mon * aMonth))
    } else {
      let aYear = 60 * 24 * 30 * 12
      let year = parseInt(m / aYear)
      return year + '年' + minute2str(m - (year * aYear))
    }
  }
}
